export const regPhone = curVal => {
	// const reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[56]|17[0135678]|18[0-9]|19[189])\d{8}$/;
	const reg = /^\d{4,18}$/;
	curVal = curVal.replace(/(^\s*)|(\s*$)/g, "")
	const bool = reg.test(curVal);
	return bool ? '' : '手机号码格式不正确';
};
export const regEmail = curVal => {
	const reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	curVal = curVal.replace(/(^\s*)|(\s*$)/g, "")
	const bool = reg.test(curVal);
	return bool ? '' : '邮箱格式不正确';
};

export const regPhoneOrEmail = curVal => {
    if (!regPhone(curVal) || !regEmail(curVal)) {
        return '';
    }
    return '手机/邮箱格式不正确';
};
export const regSum = curVal => {
	const reg = /^-?[1-9][0-9]?.?[0-9]*$/;
	const bool = reg.test(curVal);
	return bool ? '' : '请输入正确数量';
};

export const regVerification = curVal => {
	const reg = /^\d{6}$/;
	const bool = reg.test(curVal);
	return bool ? '' : '验证码不正确';
};
export const regCode = curVal => {
	const reg = /^\d{6}$/;
	const bool = reg.test(curVal);
	return bool ? '' : '验证码不正确';
};

export const regInviteCode = curVal => {
	const reg = /^[A-Za-z0-9]{8}$/;
	const bool = reg.test(curVal);
	return bool ? '' : '邀请码格式不正确';
};

export const regPwd = curVal => {
	const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z._@!]{8,20}$/
	const bool = reg.test(curVal);
	return bool ? '' : '密码为8-20位，必须含数字和字母';
};

export const regPwd2 = (curVal, curVal2) => {
	const bool = curVal == curVal2;
	return bool ? '' : '两次登录密码输入不同';
};

export const regPayPwd = (curVal, pwd) => {
	pwd = pwd | null;
	const reg = /^(\d){6}$/;
	const bool = reg.test(curVal);
	return bool ? '' : '交易密码由六位数字组成';
};
export const regPayPwd2 = (curVal, curVal2) => {
	const bool = curVal === curVal2;
	return bool ? '' : '两次交易密码输入不同';
};
export const formerPwdtwo = (curVal, curVal2) => {
	const bool = curVal === curVal2;
	return bool ? '' : '两次交易密码输入不同';
};

export const regFormerPwd= (curVal, curVal2) => {
	const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z._@!]{8,20}$/
	const bool = reg.test(curVal);
	return bool ? '' : '旧密码格式不正确';
};
export const regFormerPayPwd= (curVal, curVal2) => {
	const reg = /^(\d){6}$/;
	const bool = reg.test(curVal);
	return bool ? '' : '旧密码格式不正确';
};

export const regCoinAddres = (curVal, name) => {
		let reg = name ? /^[a-z1-5]{12,12}$/ : /^[A-Za-z0-9_:]{30,60}$/
    const bool = reg.test(curVal);
    return bool ? '' : '地址不正确';
};
export const regCoinTag = curVal => {
    const reg = /^[A-Za-z0-9]{4,18}$/;
    const bool = reg.test(curVal);
    return bool ? '' : '标签不正确';
};

export const regTBequality = (curVal, curVal2) => {
		const str_before = curVal.substring(0, 2)
　　	const str_after = curVal2.substring(0, 2)
		if (!regCoinAddres(curVal) && str_before === str_after) {
			return ''
		}
		return '地址不正确'
};

export const regIsInt = curVal => {
    const reg = /^(1|[1-9][0-9]*)$/;
    const bool = reg.test(curVal);
    return bool ? '' : '请输入整数';
};


export const regSubmit = verify => {
	const pwd = verify.pwd || '';
	const PayPwd = verify.pwdtwo || '';
	for (let i in verify) {
		switch (i) {
			case 'account':
				const rPhoneOrEmail = regPhoneOrEmail(verify[i]);
				if (rPhoneOrEmail) return rPhoneOrEmail;
				break;
			case 'phone':
				const rPhone = regPhone(verify[i]);
				if (rPhone) return rPhone;
				break;
			case 'email':
				const rEmail = regEmail(verify[i]);
				if (rEmail) return rEmail;
				break;
			case 'authCode':
				const rVerification = regVerification(verify[i]);
				if (rVerification) return rVerification;
				break;
			case 'code':
				const rCode = regCode(verify[i]);
				if (rCode) return rCode;
				break;
			case 'recode':
				const rInviteCode = regInviteCode(verify[i]);
				if (rInviteCode) return rInviteCode;
				break;
			case 'pwd':
				const rPwd = regPwd(verify[i]);
				if (rPwd) return rPwd;
				break;
			case 'pwd2':
				const rPwd2 = regPwd2(verify[i], pwd);
				if (rPwd2) return rPwd2;
				break;
			case 'pwdtwo':
				const rPayPwd = regPayPwd(verify[i], pwd);
				if (rPayPwd) return rPayPwd;
				break;
			case 'pwdtwo2':
				const rPayPwd2 = regPayPwd2(verify[i], PayPwd);
				if (rPayPwd2) return rPayPwd2;
				break;
			case 'formerPwd':
				const rFormerPwd = regFormerPwd(verify[i]);
				if (rFormerPwd) return rFormerPwd;
				break;
			case 'toAddr':
				const rCoinAddres = regCoinAddres(verify[i]);
				if (rCoinAddres) return rCoinAddres;
				break;
			case 'formerPwdtwo':
				const rFormerPayPwd = regFormerPayPwd(verify[i]);
				if (rFormerPayPwd) return rFormerPayPwd;
				break;			
			default:
		}
	}
};
